function tableData = ...
    AutocorrelationInTrees_Core(pathCellIndx, lineage_data, lineage_cellIndx, lineage_lastIndx, totalTime, nCell, lag, shrink)
%AUTOCORRELATIONIII Summary of this function goes here

% Author: Enrique Balleza

%Create bias-correction array for data from trees
nLineage = length(pathCellIndx);
nTime = totalTime-1-lag-shrink; %Added -1 becasue last df point is always NaN
tableData = NaN*ones(nLineage, nTime);
calculatedIndx = zeros(1,nCell);

%For Every Path
% lineage_data = NaN*zeros(1,totalTime);
% lineage_cellIndx = NaN*zeros(1,totalTime);
for i=1:length(pathCellIndx)
    
    indxList = pathCellIndx(i).lista;
    
%     %Construct auxiliary arrays
%     %........................................
%     lineage_lastIndx = 0;
%     for j=1:length(indxList)
%         dfT = cell_f(indxList(j),1:cellTraceL(indxList(j)));
%         n = cellTraceL(indxList(j));
%         lineage_data(lineage_lastIndx+1:n+lineage_lastIndx) = dfT;
%         lineage_cellIndx(lineage_lastIndx+1:n+lineage_lastIndx) = indxList(j);
%         lineage_lastIndx = n+lineage_lastIndx;
%     end
    
    %Truncate lineage to include only new data
    %...............................................
    %Find truncation point if any
    truncateIndx = 0;
    for j=length(indxList):-1:1
        if calculatedIndx(indxList(j)) == 1
            truncateIndx = indxList(j);
            break
        end
    end
    calculatedIndx(indxList) = 1;
    
    %Determine truncation limit
    limL = 1;
    if truncateIndx ~= 0
        limLT = find(truncateIndx==lineage_cellIndx(i,:), 1, 'last');
        limL = limLT - lag;
        if limL<1
            limL = limLT;
        end
    end
    
    %Calculate autocorr
    %.......................................
    indx_range = limL:(lineage_lastIndx(i)-lag-1-shrink);
    tableData(i,indx_range) = lineage_data(i,indx_range).*lineage_data(i,indx_range+lag);

end


end
